package com.example.config;

//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
//import org.springframework.security.web.SecurityFilterChain;
//import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
//import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
//
//import static org.springframework.security.config.Customizer.withDefaults;

/**
 * 所学内容:
 *
 * @author ..
 * @Date 2023/10/7 17:55
 */
//@Configuration
public class WebSecurityCofig {
//    @Bean
//    public WebSecurityCustomizer webSecurityCustomizer() {
//        // WebSecurityCustomizer是一个类似于Consumer<WebSecurity>的接口，函数接受一个WebSecurity类型的变量，无返回值
//        // 此处使用lambda实现WebSecurityCustomizer接口，web变量的类型WebSecurity，箭头后面可以对其进行操作
//        // 使用requestMatchers()代替antMatchers()
//        return (web) -> web.ignoring().requestMatchers(new MvcRequestMatcher(new HandlerMappingIntrospector(), "/**"));
////        return (web) -> web.ignoring().requestMatchers("/**");
//    }
//
//    @Bean
//    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
//        http
//                //使用authorizeHttpRequests()代替authorizeRequests()
//                .authorizeHttpRequests((authz) -> authz
//                        //这种写法被称为Lambda DSL，代替原来的and()链式操作
//                        .anyRequest().authenticated()
//                )
//                .httpBasic(withDefaults());
//        // 需要进行build()，返回SecurityFilterChain
//        return http.build();
//    }
}
